package cn.shanke.torrentmanagerserver.btclient.model;

import lombok.Data;
import nl.stil4m.transmission.api.domain.TorrentInfo;
import nl.stil4m.transmission.api.domain.Tracker;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Data
public class TmTorrentInfoSimple {
    private String id;
    private String name;
    private String downloadDir;
    private String hashString;
    private Long totalSize;
    private Long status;
    private Long addedDate;
    private List<Tracker> trackers;
    private Boolean isPrivate;
    private String magnetLink;

    public static TmTorrentInfoSimple wrapTransmission(TorrentInfo info) {
        TmTorrentInfoSimple tti = null;
        if (info != null) {
            tti = new TmTorrentInfoSimple();
            tti.id = info.getId() + "";
            tti.name = info.getName();
            tti.downloadDir = info.getDownloadDir();
            tti.hashString = info.getHashString();
            tti.totalSize = info.getTotalSize();
            tti.status = info.getStatus();
            tti.addedDate = info.getAddedDate();
            tti.trackers = info.getTrackers();
            tti.isPrivate = info.getPrivate();
            tti.magnetLink = info.getMagnetLink();
        }

        return tti;
    }

    public static List<TmTorrentInfoSimple> wrapTransmission(List<TorrentInfo> infos) {
        if (infos == null || infos.isEmpty()) {
            return new ArrayList<>();
        }
        return infos.stream().map(info->wrapTransmission(info)).collect(Collectors.toList());
    }
}
